const app = getApp();
const companyName = app.globalData.companyName;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oldPassword:'',
    newPassword:'',
    confirmPassword:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  inputOldPassword:function(e){
    this.setData({
      oldPassword:e.detail.value
    });
  },
  inputNewPassword: function (e) {
    this.setData({
      newPassword: e.detail.value
    });
  },
  inputConfirmPassword: function (e) {
    this.setData({
      confirmPassword: e.detail.value
    });
  },
  save:function(){
    const url = app.globalData.url;
    const oldPassword = this.data.oldPassword;
    const newPassword = this.data.newPassword;
    const confirmPassword = this.data.confirmPassword;
    if (confirmPassword !== newPassword){
      wx.showToast({
        title: '两次密码不一样',
        icon: 'none'
      })
      return;
    }
    wx.request({
      url: url + '/management/updatePassword',
      data: {
        oldPassword,
        companyName,
        newPassword
      },
      method: 'POST',
      success: function (response) {
        if (response.data.success) {
          wx.navigateBack({
            delta: 1
          });
          wx.showToast({
            title: '修改成功',
            icon: 'none'
          })
        } else {
          wx.showToast({
            title: response.data.message || '修改失败',
            icon: 'none'
          })
        }
      }
    })
  }
})